Choropleth Maps

Data

Race and Ethnicity data was pulled via API from the US Census. The data extraction and process can be find here: The Dissimilarity index was calculated using he formula found in this article:

The clean data set includes the dissimilarity index for the White population vs Black (d_wb) and the dissimilarity index for the White population vs Hispanic (d_wh).



## Segregation

Code
pal1 <- colorBin(palette = "Purples", 
                 domain = sf_state_segregation$d_wb, bins = 5, na.color = "#808080")
pal2 <-colorBin(palette = "Blues",
                domain = sf_state_segregation$d_wh, bins = 5, na.color = "#808080")
# pal3 <- colorBin(palette = "Reds", 
#                  domain = sf_state_segregation$e_b, bins = 5, na.color = "#808080")

#bins = seq(round(min, 2), round(max, 2), sep)

sf_state_segregation |> 
  leaflet() %>% 
  addProviderTiles("CartoDB.Positron") |> 
  addResetMapButton() %>% 
  #fitBounds(bbox[1], bbox[2], bbox[3], bbox[4]) |> 
  setView(-93.28260584606623,
          39.29656858589331, zoom = 4) |> 
  addPolygons(
    group="White vs Black",
    color = ~pal1(d_wb),
    weight = 1,  # border thickness
    opacity = 1, # border opacity
    fillOpacity = 0.8,
    highlightOptions = highlightOptions(fillColor ="white",
                                        bringToFront = TRUE),
    label=~paste0(state, ": ", round(d_wb, 3)),
    labelOptions = labelOptions(style = list("font-size" = "12px"))
    ) |>
  addPolygons(
    group="White vs Hispanic", 
    color = ~pal2(d_wh),
    weight = 1,  # border thickness
    opacity = 1, # border opacity
    fillOpacity = 0.8,
    highlightOptions = highlightOptions(fillColor ="white",
                                        bringToFront = TRUE),
    label=~paste0(state, ": ", round(d_wh, 2)),
    labelOptions = labelOptions(style = list("font-size" = "12px"))) |> 
    addLegend("bottomright", pal = pal2, values = ~sf_state_segregation$d_wh,
    title = "Dissiminarity Index",
    opacity = 1, group="White vs Hispanic", bins = 5) |> 
  
  addLegend("bottomright", pal = pal1, values = ~sf_state_segregation$d_wb,
    title = "Dissiminarity Index",
    opacity = 1, group="White vs Black", bins = 5) |>
  

  
  addLayersControl(baseGroups = c(
                                  "White vs Black", 
                                  "White vs Hispanic"),
                   position="bottomleft",
                   options = layersControlOptions(collapsed = F))



Income Inequality (Gini Index)

   

Sources:

- U.S. Census Bureau, American county Survey 5-Year Data (2015-2019). Retrieved from https://www.census.gov/data/developers/data-sets/acs-5year.html;
- Kyle Walker and Matt Herman (2022). tidycensus: Load US Census Boundary and Attribute Data as ‘tidyverse’ and ‘sf’-Ready Data Frames. R package version 1.2.2. https://CRAN.R-project.org/package=tidycensus;
- Kyle Walker (2022). tigris: Load Census TIGER/Line Shapefiles. R package version 1.6.1. https://CRAN.R-project.org/package=tigris.